import { useCache } from '@/hooks/useCache'

const { wsCache } = useCache()

const ACCESS_TOKEN = 'access-token'
const REFRESH_TOKEN = 'refresh-token'

/**
 * @description 获取本地存储的Token
 * @returns {string | undefined}
 */
export const getToken = () => {
  return wsCache.get(ACCESS_TOKEN)
}

/**
 * @description 设置本地存储的Token
 * @param {string} token
 * @returns {void}
 */
export const setToken = (token: string = '') => {
  wsCache.set(ACCESS_TOKEN, token)
}

/**
 * @description 删除本地存储的Token
 * @returns {void}
 */
export const removeToken = () => {
  wsCache.delete(ACCESS_TOKEN)
}

/**
 * @description 获取本地存储的RefreshToken
 * @returns {string | undefined}
 */
export const getRefreshToken = () => {
  return wsCache.get(REFRESH_TOKEN)
}

/**
 * @description 设置本地存储的RefreshToken
 * @param {string} refreshToken
 * @returns {void}
 */
export const setRefreshToken = (refreshToken: string = '') => {
  wsCache.set(REFRESH_TOKEN, refreshToken)
}

/**
 * @description 设置本地存储的RefreshToken
 * @param {string} refreshToken
 * @returns {void}
 */
export const removeRefreshToken = () => {
  wsCache.delete(REFRESH_TOKEN)
}
